home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / hershey / src / vogl.h < prev   
C/C++ Source or Header  |  1994-07-15  |  31KB  |  905 lines

  1. /* vogl.h: */
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. #ifdef AZTEC_C
  7. # ifndef AMIGA
  8. #  define AMIGA
  9. # endif
  10. #else
  11. # ifdef AMIGA
  12. #  ifndef AZTEC_C
  13. #   define AZTEC_C
  14. #  endif
  15. # endif
  16. #endif
  17.  
  18. #if defined(PC) || defined(AMIGA) || defined(AZTEC_C)
  19. #include <string.h>
  20. #else
  21. #include <strings.h>
  22. #endif
  23.  
  24. #ifdef PC    /* Stupid pox head crap */
  25. char    *vallocate();
  26. char    *malloc();
  27. #endif
  28.  
  29. #if defined(AMIGA) || defined(sgi)
  30. # ifndef __PROTOTYPE__
  31. #  define __PROTOTYPE__
  32. # endif
  33. #include "hershey.h"
  34. #endif
  35.  
  36. /*
  37.  * VOGL is always defined if a header file is from the 
  38.  * VOGL library. In cases where you do use some VOGL
  39.  * initialisation routines like vinit, just put #ifdef VOGL...
  40.  * around.
  41.  */
  42. #ifndef VOGL
  43. #define    VOGL
  44. #endif
  45.  
  46. #ifndef TRUE
  47. #define    TRUE    1
  48. #endif
  49.  
  50. #ifndef FALSE
  51. #define    FALSE    0
  52. #endif
  53.  
  54. /*
  55.  * Misc defines...
  56.  */
  57. #define    FLAT    0
  58. #define SMOOTH    1
  59. #define GD_XPMAX 1
  60. #define GD_YPMAX 2
  61.  
  62. /*
  63.  * standard colour indices
  64.  */
  65. #define    BLACK        0
  66. #define    RED        1
  67. #define    GREEN        2
  68. #define    YELLOW        3
  69. #define    BLUE        4
  70. #define    MAGENTA        5
  71. #define    CYAN        6
  72. #define    WHITE        7
  73.  
  74. /*
  75.  * when (if ever) we need the precision
  76.  */
  77. #ifdef DOUBLE
  78. #define    float    double
  79. #endif
  80.  
  81. /*
  82.  * How to convert degrees to radians
  83.  */
  84. #define    PI    3.14159265358979
  85. #define D2R    (PI / 180.0)
  86.  
  87. /*
  88.  * miscellaneous typedefs and type defines
  89.  */
  90. typedef float    Vector[4];
  91. typedef float    Matrix[4][4];
  92. typedef float    Tensor[4][4][4];
  93. typedef short    Angle;
  94. typedef float    Coord;
  95. typedef long    Icoord;
  96. typedef short    Scoord;
  97. typedef long    Object;
  98. typedef short    Screencoord;
  99. typedef long    Boolean;
  100.  
  101. typedef unsigned short    Device;
  102.  
  103. typedef unsigned short    Colorindex;
  104.  
  105.  
  106. /*
  107.  * when register variables get us into trouble
  108.  */
  109. #ifdef NOREGISTER
  110. #define    register
  111. #endif
  112.  
  113. /*
  114.  * max number of vertices in a ploygon
  115.  */
  116. #define    MAXVERTS    128
  117.  
  118. /*
  119.  * object definitions
  120.  */
  121. #define MAXENTS        101        /* size of object table */
  122. #define    MAXTOKS        100        /* num. of tokens alloced at once in
  123.                        an object  */
  124.  
  125. /*
  126.  * Polygon fill modes for "polymode"
  127.  */
  128. #define PYM_POINT    0
  129. #define PYM_LINE    0
  130. #define PYM_FILL    1
  131. #define PYM_HOLLOW    1
  132.  
  133. /*
  134.  * functions which can appear in objects
  135.  */
  136. #define    ARC        1
  137. #define    CALLOBJ        3
  138. #define    CIRCLE        5
  139. #define    CLEAR        6
  140. #define    COLOR        7
  141. #define    DRAW        8
  142. #define    DRAWSTR        10
  143. #define    FONT        12
  144. #define    LOADMATRIX    15
  145. #define    MAPCOLOR    16
  146. #define    MOVE        17
  147. #define    MULTMATRIX    18
  148. #define    POLY        19
  149. #define    POPATTRIBUTES    22
  150. #define    POPMATRIX    23
  151. #define    POPVIEWPORT    24
  152. #define    PUSHATTRIBUTES    25
  153. #define    PUSHMATRIX    26
  154. #define    PUSHVIEWPORT    27
  155. #define    RCURVE        28
  156. #define    RPATCH        29
  157. #define    SECTOR        30
  158. #define    VIEWPORT    33
  159. #define    BACKBUFFER    34
  160. #define    FRONTBUFFER    35
  161. #define    SWAPBUFFERS    36
  162. #define    BACKFACING    37
  163. #define    TRANSLATE    38
  164. #define    ROTATE        39
  165. #define    SCALE        40
  166.  
  167. #define    ARCF        41
  168. #define    CIRCF        42
  169. #define    POLYF        43
  170. #define    RECTF        44
  171.  
  172. #define    CMOV        45
  173.  
  174. /*
  175.  * States for bgn* and end* calls
  176.  */
  177. #define    NONE        0    /* Just set current spot */
  178. #define    VPNT        1    /* Draw dots         */
  179. #define    VLINE        2    /* Draw lines         */
  180. #define    VCLINE        3    /* Draw closed lines     */
  181. #define    VPOLY        4    /* Draw a polygon      */
  182.  
  183. /*
  184.  * data types for object tokens
  185.  */
  186. typedef union tk {
  187.     char    *s;
  188.     int      i;
  189.     float    f;
  190.     } Token;
  191.  
  192. typedef struct tls {
  193.     int         count;
  194.     Token      *toks;
  195.     struct tls *next;
  196.     } TokList;
  197.  
  198. /*
  199.  * double buffering modes.
  200.  */
  201. #define    SINGLEBUF        1
  202.  
  203. /*
  204.  * attributes
  205.  */
  206. typedef struct {
  207.     char    backface,
  208.         mode;            /* Which mode are we in */
  209.     int     color;
  210.     float   fontheight;
  211.     float   fontwidth;
  212.     int    fontnum;
  213.     } Attribute;
  214.  
  215. /*
  216.  * viewport
  217.  */
  218. typedef struct vp {
  219.     float    left;
  220.     float    right;
  221.     float    bottom;
  222.     float    top;
  223.     } Viewport; 
  224.  
  225. /*
  226.  * stacks
  227.  */
  228. typedef    struct    ms {    /* Matrix stack entries    */
  229.     Matrix        m;
  230.     struct    ms    *back;
  231.     } Mstack;
  232.  
  233. typedef    struct    as {    /* Attribute stack entries */
  234.     Attribute    a;
  235.     struct    as    *back;
  236.     } Astack;
  237.  
  238. typedef    struct    vs {    /* Viewport stack entries */
  239.     Viewport    v;
  240.     struct    vs    *back;
  241.     } Vstack;
  242.  
  243. /*
  244.  * vogle device structures
  245.  */
  246. #ifdef AMIGA
  247. typedef struct dev {
  248.     char    *devname;                /* name of device                        */
  249.     char    *large,                    /* name of large font                    */
  250.         *small;                        /* name of small font                    */
  251.     int    (*Vbackb)(void),            /* Set drawing in back buffer            */
  252.         (*Vchar)(char),                /* Draw a hardware character            */
  253.         (*Vcheckkey)(void),            /* Ckeck if a key was hit                */
  254.         (*Vclear)(void),            /* Clear the screen to current color    */
  255.         (*Vcolor)(int),                /* Set current color                    */
  256.         (*Vdraw)(int,int),            /* Draw a line                            */
  257.         (*Vexit)(void),                /* Exit graphics                        */
  258.         (*Vfill)(int,int[],int[]),    /* Fill a polygon                        */
  259.         (*Vfont)(char *),            /* Set hardware font                    */
  260.         (*Vfrontb)(void),            /* Set drawing in front buffer            */
  261.         (*Vgetkey)(void),            /* Wait for and get the next key hit    */
  262.         (*Vinit)(void),                /* Initialise the device                */
  263.         (*Vlocator)(int *,int*),    /* Get mouse/cross hair position        */
  264.         (*Vmapcolor)(int,int,int,int),/* Set color indicies                    */
  265.         (*Vstring)(char *),            /* Draw a hardware string                */
  266.         (*Vswapb)(void);            /* Swap front and back buffers            */
  267.     } DevEntry;
  268. #else
  269. typedef struct dev {
  270.     char    *devname;        /* name of device                        */
  271.     char    *large,            /* name of large font                    */
  272.         *small;                /* name of small font                    */
  273.     int    (*Vbackb)(),        /* Set drawing in back buffer            */
  274.         (*Vchar)(),            /* Draw a hardware character            */
  275.         (*Vcheckkey)(),        /* Ckeck if a key was hit                */
  276.         (*Vclear)(),        /* Clear the screen to current color    */
  277.         (*Vcolor)(),        /* Set current color                    */
  278.         (*Vdraw)(),            /* Draw a line                            */
  279.         (*Vexit)(),            /* Exit graphics                        */
  280.         (*Vfill)(),            /* Fill a polygon                        */
  281.         (*Vfont)(),            /* Set hardware font                    */
  282.         (*Vfrontb)(),        /* Set drawing in front buffer            */
  283.         (*Vgetkey)(),        /* Wait for and get the next key hit    */
  284.         (*Vinit)(),            /* Initialise the device                */
  285.         (*Vlocator)(),        /* Get mouse/cross hair position        */
  286.         (*Vmapcolor)(),        /* Set color indicies                    */
  287.         (*Vstring)(),        /* Draw a hardware string                */
  288.         (*Vswapb)();        /* Swap front and back buffers            */
  289.     } DevEntry;
  290. #endif
  291.  
  292. typedef struct vdev {
  293.     char        initialised,
  294.                 clipoff,
  295.                 inobject,
  296.                 inpolygon,
  297.                 fill,            /* polygon filling                        */
  298.                 cpVvalid,        /* is the current device position valid */
  299.                 inbackbuffer,    /* are we in the backbuffer                */
  300.                 clipplanes;        /* active clipping planes                */
  301.     void        (*pmove)(),        /* Polygon moves                        */
  302.                 (*pdraw)();        /* Polygon draws                        */
  303.     TokList        *tokens;        /* ptr 2 list of tokens for current object */
  304.     Mstack        *transmat;        /* top of transformation stack            */
  305.     Astack        *attr;            /* top of attribute stack                */
  306.     Vstack        *viewport;        /* top of viewport stack                */
  307.     float        hheight, hwidth;/* hardware character height, width        */
  308.     Vector        cpW,            /* current postion in world coords        */
  309.                 cpWtrans,        /* current world coords transformed        */
  310.                 upvector;        /* world up                                */
  311.     int            depth,            /* # bit planes on screen                */
  312.                 maxVx, minVx,
  313.                 maxVy, minVy,
  314.                 sizeX, sizeY,     /* size of square on screen                */
  315.                 sizeSx, sizeSy,    /* side in x, side in y (# pixels)        */
  316.                 cpVx, cpVy;
  317.     DevEntry    dev;
  318.     float        savex,            /* Where we started for v*()            */
  319.                 savey,
  320.                 savez;
  321.     char        bgnmode;        /* What to do with v*() calls            */
  322.     char        save;            /* Do we save 1st v*() point            */
  323.  
  324.     char        *wintitle;        /* window title                            */
  325.  
  326.     char        *devname;        /* pointer to device name                */
  327.  
  328.     Matrix        tbasis, ubasis, *bases; /* Patch stuff                    */
  329.     
  330.     char        *enabled;        /* pointer to enabled devices mask        */
  331.     int            maxfontnum;
  332.  
  333.     char        alreadyread;    /* queue device stuff                    */
  334.     char        kbdmode;        /* are we in keyboard mode                */
  335.     char        mouseevents;    /* are mouse events enabled                */
  336.     char        kbdevents;        /* are kbd events enabled                */
  337.     int            devno, data;
  338.  
  339.     int            concave;        /* concave polygons?                    */
  340.  
  341.     } VDevice;
  342.  
  343. extern VDevice    vdevice;        /* device structure                        */
  344.  
  345. #define    V_X    0            /* x axis in cpW */
  346. #define    V_Y    1            /* y axis in cpW */
  347. #define    V_Z    2            /* z axis in cpW */
  348. #define    V_W    3            /* w axis in cpW */
  349.  
  350. #ifdef __PROTOTYPE__
  351.  
  352. void arcprecision(int);                                /* arcs.c          */
  353. void circleprecision(int);                             /* arcs.c          */
  354. void arc( Coord, Coord, Coord, Angle, Angle);          /* arcs.c          */
  355. void arcs( Scoord, Scoord, Scoord, Angle, Angle);      /* a